import { _decorator, Component, instantiate, Label, Node, tween, UIOpacity, v3 } from 'cc';
const { ccclass, property } = _decorator;



@ccclass('TurkishTetrisTipScorePanel')
export default class TurkishTetris_TipScorePanel extends Component {
    static Instance: TurkishTetris_TipScorePanel;
    @property(Node)
    parent: Node | null = null;
    @property(Node)
    Prefab: Node | null = null;
    array: Node[] = new Array();
    onLoad() {
        TurkishTetris_TipScorePanel.Instance = this;
    }
    start() { }
    Show(content: string, duration = 0.4) {
        const node: Node = instantiate(this.Prefab);
        let label = node.getComponentInChildren(Label);
        if (!label) {
            label = node.addComponent(Label);
        }

        this.DestroyAll();
        this.array.push(node);

        label.string = content;
        node.parent = this.parent;
        node.setPosition(0, 0);
        node.active = true;
        node.scale = v3(0.2, 0.2, 0.2);
        node.getComponent(UIOpacity).opacity = 0;


        tween(node)
            // .to(0.3, { scale: 1.4, opacity: 255 }, { easing: "" })
            // .to(0.2, { scale: 1 }, { easing: "" })
            // .to(0.2, { scale: 1.1 }, { easing: "" })
            // .to(0.2, { scale: 1 }, { easing: "" })
            // .to(0.2, { scale: 1.1 }, { easing: "" })
            // .to(0.2, { scale: 1 }, { easing: "" })
            .to(0.3, { scale: v3(1.4, 1.4, 1.4,) },)
            .to(0.2, { scale: v3(1, 1, 1,) },)
            .to(0.2, { scale: v3(1.1, 1.1, 1.1,) },)
            .to(0.2, { scale: v3(1, 1, 1,) },)
            .to(0.2, { scale: v3(1.1, 1.1, 1.1,) },)
            .to(0.2, { scale: v3(1, 1, 1,) },)

            .delay(duration)
            // .to(0.2, { opacity: 0 }, { easing: "" })
            .call(() => {
                this.DestroyAll();
            })
            .start();

        tween(node.getComponent(UIOpacity))
            .delay(1.3 + duration)
            .to(0.2, { opacity: 0 },)
            .start();
    }
    DestroyAll() {
        this.array.forEach((element) => {
            element.destroy();
        });
        this.array = new Array();
    }
}

// /** 调试 */
window["TurkishTetris_TipScorePanel"] = TurkishTetris_TipScorePanel;